package likouJava;

public class 旋转图像 {
    public void rotate(int[][] matrix) {
        int n = matrix.length;

        //矩阵反转
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int temp = matrix[i][j];
                matrix[i][j] = matrix[j][i];
                matrix[j][i] = temp;
            }
        }

        //每一行反转
        for (int i = 0; i < n; i++) {
            int left  = 0,right = n - 1;
            while (left < right){
                int temp = matrix[i][left];
                matrix[i][left] = matrix[i][right];
                matrix[i][right] = temp;
                left ++;
                right --;
            }
        }
    }

}
